﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.FrameWork
{
    /// <summary>
    /// 
    /// </summary>
    public static class UseStartupExtension
    {
        /// <summary>
        /// 指定win主机要使用的启动类型。
        /// </summary>
        /// <typeparam name="IStartup">包含应用程序启动方法的类型。</typeparam>
        /// <param name="hostBuilder">IWinHostBuilder配置</param>
        /// <returns></returns>
        public static IHostBuilder UseStartup<IStartup>(this IHostBuilder hostBuilder) where IStartup : class, new()
        {
            DefaultHostBuilder winHostBuilder = hostBuilder as DefaultHostBuilder;
            if (hostBuilder != null)
                winHostBuilder.Startup = new IStartup();
            return hostBuilder;
        }

        /// <summary>
        /// 指定win主机要使用的启动类型。
        /// </summary>
        /// <param name="hostBuilder">IWinHostBuilder配置</param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static IHostBuilder ConfigureWinHostDefaults(this IHostBuilder hostBuilder, Action<IHostBuilder> configure)
        {
            configure.Invoke(hostBuilder);
            DefaultHostBuilder winHostBuilder = hostBuilder as DefaultHostBuilder;
            return hostBuilder;
        }
    }
}
